package com.bdqn.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bdqn.pojo.Role;
import com.bdqn.service.RoleService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

/**
 * RoleController
 *
 * @author LILIBO
 * @since 2024-01-18
 */
@Controller
@RequestMapping("/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    /**
     * 角色列表
     */
    @RequestMapping("/list")
    public String list(Model model, String roleName, @RequestParam(required = false, defaultValue = "1") Long pageIndex) {
        // ① 数据回显
        model.addAttribute("roleName", roleName);

        // ② 根据条件进行分页查询
        Page page = new Page(pageIndex, 5);
        Page<Role> rolePager = roleService.getPage(roleName, page);
        model.addAttribute("rolePager", rolePager); // 将数据设置到作用域

        return "role/list";
    }

}
